package com.ruoyi.web.controller.index;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.dto.StringIntegerMapDto;
import com.ruoyi.task.service.ITaskCommentService;
import com.ruoyi.task.service.ITaskService;
import com.ruoyi.wechat.service.IWechatUserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 微信用户Controller
 *
 * @author KevenPotter
 * @date 2024-05-01 20:09:47
 */
@RestController
@RequestMapping("/index")
@AllArgsConstructor
public class IndexController extends BaseController {

    private final IWechatUserService wechatUserService;
    private final ITaskService taskService;
    private final ITaskCommentService taskCommentService;

    /**
     * 获取首页基本数据
     *
     * @author KevenPotter
     * @date 2024-05-01 20:11:25
     */
    @GetMapping("/basicInfo")
    public AjaxResult basicInfo() {
        int wechatUserCounts = wechatUserService.getWechatUserCounts();
        int taskCounts = taskService.getTaskCounts();
        int taskFeaturedCounts = taskService.getTaskFeaturedCounts();
        int taskCommentCounts = taskCommentService.getTaskCommentCounts();
        Map<String, Integer> resultMap = new HashMap<>();
        resultMap.put("wechatUserCounts", wechatUserCounts);
        resultMap.put("taskCounts", taskCounts);
        resultMap.put("taskFeaturedCounts", taskFeaturedCounts);
        resultMap.put("taskCommentCounts", taskCommentCounts);
        return AjaxResult.success(resultMap);
    }

    /**
     * 获取首页近期评论数据
     *
     * @author KevenPotter
     * @date 2024-05-01 20:12:13
     */
    @GetMapping("/recentlyCommentCounts")
    public AjaxResult recentlyCommentCounts() {
        List<StringIntegerMapDto> recentlyCommentCountList = taskCommentService.getRecentlyCommentCounts();
        return AjaxResult.success(recentlyCommentCountList);
    }

}
